﻿using System;
using System.Collections.Generic;
using System.Text;
using WeatherSystem.Application.Model;
using WeatherSystem.Application.MsgHandler;
using WeatherSystem.Data.Response;

namespace WeatherSystem.Application.ContentAdapter.EventAdapter
{
    class ClickAdapter : EventAdapterBase
    {
        public override string EventName => "CLICK";

        public override ResponseMessageBase Handle(Message message)
        {
            var msg = message as EventMessage;
            TextMsg response;
            switch (msg.EventKey)
            {
                case "key_data_recent":
                    response = HandleDataRecent(msg);
                    break;
                case "key_data_analyse":
                    response = HandleDataAnalyse(msg);
                    break;
                case "key_data_time":
                    response = HandleDataTime(msg);
                    break;
                default:
                    var str = "未知点击事件";
                    response = new TextMsg(msg.FromUserName, msg.ToUserName, Data.Convert.ToTimeStamp(DateTime.Now), str);
                    break;
            }
            return response;
        }

        private TextMsg HandleDataRecent(EventMessage msg)
        {
            var data_model = new DataModel();
            var user_model = new UserModel();
            var device_select = user_model.Select("name", msg.FromUserName);
            var device = device_select[0]["device"].ToString();
            var data_select = data_model.Select("device", device);
            var data = data_select[0];
            var str = Data.Convert.WeatherDataToString(data);
            return new TextMsg(msg.FromUserName, msg.ToUserName, Data.Convert.ToTimeStamp(DateTime.Now), str);
        }

        private TextMsg HandleDataTime(EventMessage msg)
        {
            var str = @"<a href=""https://w.url.cn/s/A5JlDOn"">点击这里进行高级数据管理</a>";
            return new TextMsg(msg.FromUserName, msg.ToUserName, Data.Convert.ToTimeStamp(DateTime.Now), str);
        }

        private TextMsg HandleDataAnalyse(EventMessage msg)
        {
            var str = "该功能开发中，敬请期待！";
            return new TextMsg(msg.FromUserName, msg.ToUserName, Data.Convert.ToTimeStamp(DateTime.Now), str);
        }
    }
}
